//
//  MessageDetailViewController.m
//  WDFans
//
//  Created by Zhihong Yuan on 2/24/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "MessageDetailViewController.h"
#import "WDUserMessage.h"
#import "ZHWebService.h"
#import "ZHDataService.h"
#import "ActivityViewManager.h"

@interface MessageDetailViewController ()
- (void)fillMessageViewContent;
@end

@implementation MessageDetailViewController

@synthesize message,isForRead;
@synthesize titleLabel,contentTextView,dateLabel;

#pragma mark - my own methods
- (void)fillMessageViewContent
{
    //set content for the view
    self.titleLabel.text = self.message.mesTitle;
    
    self.contentTextView.text = self.message.mesContent;
    NSString *date = @"";
    if(self.message.mesDate != nil)
    {
        NSArray *ta = [self.message.mesDate componentsSeparatedByString:@" "];
        date = [ta objectAtIndex:0];
    }
    self.dateLabel.text = date;
    
//    if(self.isForRead)
//        [self addNaviBarRightItemWithTitle:@"设置已读"];
}

#pragma mark - AbstractTabViewController methods
- (IBAction)rightItemClicked
{
    CompletionBlock completion = ^(NSData *data)
    {
        if([ZHDataService setMessageReadSucceed:data])
        {
            //[ActivityViewManager showErrorViewWithMessage:@"设置成功！"];
            //self.navigationItem.rightBarButtonItem = nil;
        }
        else
        {
            //[ActivityViewManager showErrorViewWithMessage:@"设置失败！"];
        }
    };
    ErrorBlock error = ^(NSString *error){};
    [[ZHWebService sharedService] setPersonalMessageIsReadWithMesId:self.message.mesId onCompletion:completion onError:error];
}

#pragma mark - View lifecycle
- (void)dealloc
{
    [dateLabel release];
    [titleLabel release];
    [contentTextView release];
    [message release];
    [super dealloc];
}

- (id)initWithMessage:(WDUserMessage *)mes
{
    self = [super initWithNibName:@"MessageDetailViewController" bundle:nil];
    if (self) {
        // Custom initialization
        self.message = mes;
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title = @"消息内容";
    [self setBackgroundImageViewForTabView];
    [self rightItemClicked];
    [self fillMessageViewContent];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
    self.titleLabel = nil;
    self.contentTextView = nil;
    self.dateLabel = nil;
}

@end
